#include "led.h"
#include "reg.h"
volatile int i = 0x30313233;

void led_delay(uint32_t delay)
{
  uint32_t _delay = delay;
  for (i = 6; i < _delay; i++)
  {
    asm("NOP");
  }
}

// PC0 低电平亮
#define LED_ON() GPIOC->BCR = 1 << 0   // PC0 set
#define LED_OFF() GPIOC->BSHR = 1 << 0 // PC0 reset

void led_init()
{
  // 使能APB2 PC 时钟
  RCC->APB2PCENR |= 1 << 4;

  // mode0[0:1]
  GPIOC->CFGLR |= (0x03 << 0); //   00：通用推挽输出模式

  // cfn0[2:3]
  GPIOC->CFGLR &= ~(0x03 << 2); //  11：输出模式，最大速度 50MHz  PC0  输出

  LED_ON();
}

void led_flash_loop()
{
  led_init();
  while (1)
  {

    LED_ON();
    led_delay(50000);
    LED_OFF();
    led_delay(50000);

    LED_ON();
    led_delay(50000);
    LED_OFF();
    led_delay(50000);

    led_delay(700000);
  }
}
